##############################################################
#Figure B1: Estimated Democrat Senate Share and Turnout
##############################################################

sen.prec <- read.dta13("./temp/figb1adata.dta")

newdf <- sen.prec %>% 
  gather(variable, value, -var)%>%
  spread(var, value)

newdf$id <- c(5,4,3,2,6,1)

g<- ggplot() + 
  geom_pointrange(data=newdf, mapping=aes(x=id, y=coef, ymin=ci_upper, 
                                          ymax=ci_lower), color="grey60", size=1.2, fatten=2, fill="goldenrod1", shape=21) +
  ylim(-.15,.05) +
  scale_x_discrete(limit=c("1", "2", "3", "4", "5", "6"), labels= c("[500,30)", "[400,30)", "[300,30)", "[200,30)", "[100,30)", "[50,30)")) + 
  xlab("Distance Band")  + ylab("Estimate on Democrat Share U.S. Senate") +
  geom_hline(yintercept=0, col="grey60", lwd=1, lty="dashed", alpha=.6)  + 
  ggtitle("Wind >64kt") + theme(plot.title = element_text(hjust = .5, face="bold", size=15, colour = "grey60"),
                                axis.text= element_text(size = 12),
                                axis.title = element_text(size=15)) 
g

rm(newdf, sen.prec)
sen.prec.major <- read.dta13("./temp/figb1bdata.dta")


newdf <- sen.prec.major %>% 
  gather(variable, value, -var)%>%
  spread(var, value)

newdf$id <- c(5,4,3,2,6,1)

g2<- ggplot() + 
  geom_pointrange(data=newdf, mapping=aes(x=id, y=coef, ymin=ci_upper, 
                                          ymax=ci_lower), color="grey60", size=1.2, fatten=2, fill="goldenrod1", shape=21) +
  ylim(-.15,.05) +
  scale_x_discrete(limit=c("1", "2", "3", "4", "5", "6"), labels= c("[500,30)", "[400,30)", "[300,30)", "[200,30)", "[100,30)", "[50,30)")) + 
  xlab("Distance Band")  + ylab("Estimate on Democrat Share U.S. Senate") +
  ggtitle("Wind >96kt") + theme(plot.title = element_text(hjust = .5, face="bold", size=15, colour = "grey60"), axis.text= element_text(size = 12),
                                axis.title = element_text(size=15)) + 
  geom_hline(yintercept=0, col="grey60", lwd=1, lty="dashed", alpha=.6)  
g2

library(ggpubr)
ggarrange(g,g2)
ggsave(file="./figures/figb1.pdf")